#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Solution {
public:
    int findTargetSumWays(vector<int>& nums, int target) {
        int count = 0;
        backtrack(nums, target, count, 0, 0);
        return count;
    }
private:
    void backtrack(vector<int>& nums, int target,int&count,int sum,int index ) {
        if (nums.size() == index) {
            if (sum == target) { count++; }
            return;
        }
        backtrack(nums, target, count, sum+nums[index], index+1);
        backtrack(nums, target, count, sum-nums[index], index+1);
    }
};